#include <iostream>
#include <set>
#include <vector>
#include <iterator>
#include <chrono>
#include <sw/redis++/redis++.h>


using namespace std;
using namespace sw::redis;
using namespace chrono_literals; //字面常量 1s 1000ms


void test(Redis & redis)
{
    cout << "getrange and setrange" << endl;

    redis.set("key", "1e1ewqdwdsadadwdwds");

    auto str = redis.getrange("key", 3, 7);
    cout << "str: " << str << endl;
    
    auto result = redis.setrange("key", 4, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    cout << "setrange: " << result <<endl;
    
    auto value = redis.get("key");
    cout << "value: " << value.value() << endl;
}   

void test1(Redis& redis)
{

    cout << "nx and xx" << endl;

    redis.flushall();

    redis.set("key", "lr", 0s, UpdateType::EXIST);

    auto result = redis.get("key");
    if(result)
    {
        cout << "result: " << result.value() << endl; 
    }else{
        cout << "result 无效！！！" << endl;
    }

    
    redis.set("key", "zx", 0s, UpdateType::NOT_EXIST);

    result = redis.get("key");
    if(result)
    {
        cout << "result: " << result.value() << endl; 
    }else{
        cout << "result 无效！！！" << endl;
    }
    
}

int main()
{
    Redis redis("tcp://127.0.0.1:6379");
    test1(redis);
    return 0;
}